<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%">
          <el-table-column label="投诉人头像" align="center" min-width="120">
            <template slot-scope="scope">
              <img class="pic_pay user_img" :src="$fnc.getImgUrl(scope.row.avatar)" />
            </template>
          </el-table-column>

          <el-table-column label="投诉人" min-width="150">
            <template slot-scope="scope">
              <div class="user_table">
                <span>投诉人昵称&nbsp;&nbsp;</span>
                <small>{{ scope.row.nickname || "xxx" }}</small>
                <br />
                <span>投诉人账号&nbsp;&nbsp;</span>
                <small>{{ scope.row.username }}</small>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="被投诉人头像" align="center" min-width="120">
            <template slot-scope="scope">
              <img class="pic_pay user_img" :src="$fnc.getImgUrl(scope.row.shop_avatar)" />
            </template>
          </el-table-column>

          <el-table-column label="被投诉人" min-width="150">
            <template slot-scope="scope">
              <div class="user_table">
                <span>被投诉人昵称&nbsp;&nbsp;</span>
                <small>{{ scope.row.shop_nickname || "xxx" }}</small>
                <br />
                <span>被投诉人账号&nbsp;&nbsp;</span>
                <small>{{ scope.row.shop_username }}</small>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="投诉信息" min-width="160">
            <template slot-scope="scope">
              <div class="user_table">
                <span>投诉类型：</span>
                <small>{{ scope.row.title }}</small>
                <br />
                <span>投诉内容：</span>
                <small>{{ scope.row.content }}</small>
                <br />
                <span>投诉时间：</span>
                <small>{{ scope.row.created_time | getTimeFormat }}</small>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="投诉状态" min-width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.is_check == 1" type="success" effect="dark">已处理</el-tag>
              <el-tag v-else type="warning" effect="dark">未处理</el-tag>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="140">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" size="mini" type="primary" @click="
                  showDio(scope.row.id, scope.row.is_check, scope.row.remark)
                ">编辑</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="delSupplierComplaint(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="供应商" :modal-append-to-body="false" :visible.sync="show" class="tl size_13" width="800px">
      <el-form :model="data" ref="data" class="mar_top" label-width="120px">
        <el-form-item label="审核" prop="remark">
          <el-col :span="12">
            <el-radio-group v-model="data.is_check">
              <el-radio label="0">未处理</el-radio>
              <el-radio label="1">已处理</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-col :span="12">
            <el-input placeholder="请输入备注" type="textarea" v-model="data.remark" clearable></el-input>
          </el-col>
        </el-form-item>
        
        <el-form-item>
          <el-button :loading="$store.state.isLoading" size="medium" type="primary" @click.prevent="addUpdate">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { suppliercomplaintSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      userSearchData: suppliercomplaintSearchData,
      list: [],
      pageSize: 10,
      currentPage: 1,
      loading: false,
      show: false,
      data: {
        remark: "",
        is_check: "0"
      },
      searchAll: {}
    };
  },
  created () {
    this.getNewsAll();
  },
  methods: {
    getSearch (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      console.log(val);
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = data || {};
      params.iden = this.$route.query.iden;
      this.$api.getSupplier.getSupplierComplaint(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    showDio (id, is_check, remark) {
      this.data.id = id;
      this.data.is_check = is_check;
      this.data.remark = remark;
      this.show = true;
    },
    addUpdate () {
      this.show = false;
      this.$api.getSupplier.setSupplierComplaint(this.data).then(res => {
        this.getNewsAll(this.searchAll);
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: res.data.code_desc });
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    delSupplierComplaint (id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: id };
          this.$api.getSupplier.delSupplierComplaint(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    }
  },
  watch: {
    $route () {
      this.getNewsAll();
    }
  }
};
</script>
